1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package com.google.common.collect;
16
17 import com.google.common.annotations.GwtCompatible;
18 import com.google.common.annotations.GwtIncompatible;
19
20 import java.util.Comparator;
21
22 import javax.annotation.Nullable;
23
24
25
26
27
28
29
30 @GwtCompatible(emulated = true)
31 @SuppressWarnings("serial")
32 final class ImmutableSortedAsList<E> extends RegularImmutableAsList<E>
33 implements SortedIterable<E> {
34 ImmutableSortedAsList(
35 ImmutableSortedSet<E> backingSet, ImmutableList<E> backingList) {
36 super(backingSet, backingList);
37 }
38
39 @Override
40 ImmutableSortedSet<E> delegateCollection() {
41 return (ImmutableSortedSet<E>) super.delegateCollection();
42 }
43
44 @Override public Comparator<? super E> comparator() {
45 return delegateCollection().comparator();
46 }
47
48
49
50 @GwtIncompatible("ImmutableSortedSet.indexOf")
51
52 @Override public int indexOf(@Nullable Object target) {
53 int index = delegateCollection().indexOf(target);
54
55
56
57
58
59
60 return (index >= 0 && get(index).equals(target)) ? index : -1;
61 }
62
63 @GwtIncompatible("ImmutableSortedSet.indexOf")
64 @Override public int lastIndexOf(@Nullable Object target) {
65 return indexOf(target);
66 }
67
68 @Override
69 public boolean contains(Object target) {
70
71 return indexOf(target) >= 0;
72 }
73
74 @GwtIncompatible("super.subListUnchecked does not exist; inherited subList is valid if slow")
75
76
77
78
79
80 @Override
81 ImmutableList<E> subListUnchecked(int fromIndex, int toIndex) {
82 return new RegularImmutableSortedSet<E>(
83 super.subListUnchecked(fromIndex, toIndex), comparator())
84 .asList();
85 }
86 }